//
//  SecondViewController.m
//  个人项目(豆瓣元旦作业)
//
//  Created by dllo on 16/1/4.
//  Copyright © 2016年 guoguo. All rights reserved.
//

#import "SecondViewController.h"
#import "UIImageView+WebCache.h"
#import "HGDataBase.h"
#import "Movie.h"
@interface SecondViewController ()

@property (nonatomic ,copy) NSString *str;

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = _model.title;
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_nav_share@2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
    
    
    self.navigationItem.rightBarButtonItem = item;
    
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    
    scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height * 3);
    
    
    [self.view addSubview:scrollView];
    
    
    
    
    
    UIImageView *image1 = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 130, 190)];
    
    NSDictionary *dic = _model.images;
    NSString *result = dic[@"large"];
    [image1 sd_setImageWithURL:[NSURL URLWithString:result]];
    
    [scrollView addSubview:image1];
    
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(170, 20, 50, 40)];
    label.backgroundColor = [UIColor whiteColor];
    label.text = @"评分:";
    
    [scrollView addSubview:label];
    
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(220, 20, 50, 40)];
    
    label1.text = _model.rating;
    
    [scrollView addSubview:label1];
    
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(250, 20, 100, 40)];
    
    NSString *str1 = [_model.wish stringValue];
    
    
    NSString *str = [str1 stringByAppendingString:@"评论"];
    
    
    label2.text =str;
    
    
    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(170, 50, 100, 40)];
    label3.text = _model.pubdate;
    
    [scrollView addSubview:label3];
    
    
    UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(170, 80, 100, 40)];
    label4.text = @"120min";
    
    [scrollView addSubview:label4];
    
    
    UILabel *label5 = [[UILabel alloc] initWithFrame:CGRectMake(170, 110, 120, 40)];
    label5.text = @"动作/冒险/惊悚";
    [scrollView addSubview:label5];
    
    UILabel *label6 = [[UILabel alloc] initWithFrame:CGRectMake(170, 140, 100, 40)];
    label6.text = @"美国/法国";
    [scrollView addSubview:label6];
    
    
    
}


- (void)itemAction:(UIBarButtonItem *)item{
    
    NSArray *arr = [[HGDataBase sharedHGDataBase] selectData];
    
    NSMutableArray *arrTitle = [NSMutableArray array];
    
    for (Movie *model in arr) {
        NSString *str = model.title;
        
        [arrTitle addObject:str];
    }
    
    if (![arrTitle containsObject:_model.title]) {
        
        [[HGDataBase sharedHGDataBase] insertData:_model];
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"收藏成功" preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            _str = @"haha";
            
            
        }];
        
        
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alert addAction:action];
        [alert addAction:action1];
        
        
        [self presentViewController:alert animated:YES completion:nil];
        
    }else{
        
    
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"该活动已被收藏过" preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    
                }];
                
                [alert addAction:action];
                [self presentViewController:alert  animated:YES completion:^{
                    
                }];
                
        
            
        
        
        
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
